﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Elentok.Common.Wpf.Dialogs
{
  /// <summary>
  /// Interaction logic for SelectEncodingDialog.xaml
  /// </summary>
  public partial class SelectEncodingDialog : Window
  {
    /// <summary>
    /// Initializes a new instance of the <see cref="SelectEncodingDialog"/> class.
    /// </summary>
    public SelectEncodingDialog()
    {
      InitializeComponent();

      this.DataContext = new SelectEncodingDialogViewModel();
    }

    /// <summary>
    /// Gets the view model.
    /// </summary>
    /// <value>The view model.</value>
    public ISelectEncodingDialogViewModel ViewModel
    {
      get
      {
        return (ISelectEncodingDialogViewModel)this.DataContext;
      }
    }

    private void okButton_Click(object sender, RoutedEventArgs e)
    {
      DialogResult = true;
      Close();
    }

    private void EncodingViewSource_Filter(object sender, FilterEventArgs e)
    {
      var encodingInfo = (EncodingInfo)e.Item;

      if (string.IsNullOrEmpty(ViewModel.FilterText))
        e.Accepted = true;
      else
      {
        e.Accepted = encodingInfo.DisplayName.ToUpperInvariant()
          .Contains(ViewModel.FilterText.ToUpperInvariant());
      }
    }
  }
}
